package com.prs.crm.domain.pm;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.BaseEntity;
import com.prs.crm.domain.hr.Person;

@Entity
@Table(name="pm_group")
public class PmGroup extends BaseEntity{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String name;
	@ManyToOne
	private PmSpecialty specialty;
	@ManyToOne
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Attachment attach;
	@ManyToOne
	private Person principal;
	@Lob
	private String summary;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="group")
	private Set<PmGroupMember> members;
	
	public void addMember(PmGroupMember member) {
		if(members == null) {
			members = new HashSet<PmGroupMember>();
		}
		members.add(member);
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public PmSpecialty getSpecialty() {
		return specialty;
	}
	public void setSpecialty(PmSpecialty specialty) {
		this.specialty = specialty;
	}
	public Attachment getAttach() {
		return attach;
	}
	public void setAttach(Attachment attach) {
		this.attach = attach;
	}
	public Person getPrincipal() {
		return principal;
	}
	public void setPrincipal(Person principal) {
		this.principal = principal;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public void setMembers(Set<PmGroupMember> members) {
		this.members = members;
	}
	public Set<PmGroupMember> getMembers() {
		return members;
	}
	
}
